package com.youu.youu.manager.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.abel533.entity.Example;
import com.github.abel533.entity.Example.Criteria;
import com.youu.youu.manager.bean.TScenicdetails;
import com.youu.youu.manager.dao.TScenicdetailsMapper;
import com.youu.youu.manager.service.ScenicdetailsService;

@Service
public class ScenicdetailsServiceImpl implements ScenicdetailsService {
    
    @Autowired
    TScenicdetailsMapper scenicdetailsMapper;

    /**
     * 获取所有景点详情
     * @Description (TODO这里用一句话描述这个方法的作用)
     * @return
     */
    @Override
    public List<TScenicdetails> getList() {
        List<TScenicdetails> list = scenicdetailsMapper.select(null);
        System.out.println(list);
        return list;
    }

    /**
     * 删除一个景点
     * @Description (TODO这里用一句话描述这个方法的作用)
     * @param mid
     * @return
     */
    @Override
    public boolean delete(Integer mid) {
        int i = scenicdetailsMapper.deleteByPrimaryKey(mid);
        return i>0?true:false;
    }

    /**
     * 添加一个景点
     * @Description (TODO这里用一句话描述这个方法的作用)
     * @param scen
     * @return
     */
    @Override
    public boolean addScen(TScenicdetails scen) {
        return scenicdetailsMapper.insertSelective(scen)>0;
    }

    /**
     * 修改一个景点
     * @Description (TODO这里用一句话描述这个方法的作用)
     * @param scen
     * @return
     */
    @Override
    public boolean updateScen(TScenicdetails scen) {
        return scenicdetailsMapper.updateByPrimaryKeySelective(scen)>0;
    }

    /**
     * 根据省和市查询景点
     * @Description (TODO这里用一句话描述这个方法的作用)
     * @param scen
     * @return
     */
	@Override
	public List<TScenicdetails> getScnList(TScenicdetails scen) {
		// TODO Auto-generated method stub
		String province = scen.getProvince();
		String city = scen.getCity();
		Example example = new Example(TScenicdetails .class);
		Criteria criteria01 = example.createCriteria();
		Criteria criteria02 = example.createCriteria();
		criteria02.andLike("province", "%"+province+"%");
		criteria02.andLike("city", "%"+city+"%");
		example.or(criteria02);
		return scenicdetailsMapper.selectByExample(example);
	}
	
	/**
     * 根据多个条件查询景点
     * @Description (TODO这里用一句话描述这个方法的作用)
     * @param scen
     * @return
     */
    @Override
    public List<TScenicdetails> getScnListByBatch(TScenicdetails scen) {
        String province = scen.getProvince();
        String city = scen.getCity();
        Example example = new Example(TScenicdetails.class);
        Criteria criteria01 = example.createCriteria();
        Criteria criteria02 = example.createCriteria();
        Criteria criteria03 = example.createCriteria();
        Criteria criteria04 = example.createCriteria();
        
        criteria01.andLike("province", "%"+province+"%");
        criteria02.andLike("city", "%"+city+"%");
        criteria03.andLike("scenicName", "%" + scen.getScenicName() + "%");
        criteria04.andLike("scenicLocation", "%" + scen.getScenicLocation() + "%");
        example.or(criteria02);
        example.or(criteria03);
        example.or(criteria04);
        return scenicdetailsMapper.selectByExample(example);
    }
	
}
